<template>
  <el-radio-group v-bind="$attrs" :value="value" v-on="$listeners">
    <component
      :is="radioCmpt"
      v-for="item in options"
      :key="item.value"
      :disabled="!!item.disabled"
      :label="item.value"
    >
      {{ item.label }}
    </component>
  </el-radio-group>
</template>

<script>
import { isPlainObject } from '@/common/plugins/tools/type'
import { toOptions } from './tags'

export default {
  name: 'CRadioGroup',
  data() {
    return {}
  },
  props: {
    value: {
      default: '',
    },
    numberKey: Boolean,
    isButton: Boolean,
  },
  computed: {
    radioCmpt() {
      return this.isButton ? 'el-radio-button' : 'el-radio'
    },
    options() {
      const { options } = this.$attrs
      return isPlainObject(options) ? toOptions(options, this.numberKey) : options || []
    },
  },
}
</script>
